﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using TransactionServer.General_Classes;
using System.ComponentModel;
using Microsoft.VisualBasic.Activities;

namespace TransactionServer.CRM4Activities
{
    [Designer(typeof(TransactionServer.ActivityDesign.CRM4Activities.CRM4GetLinkToEntity))]
    public sealed class CRM4GetLinkToEntity : CodeActivity
    {
        [RequiredArgument]
        public InArgument<Context> Context { get; set; }
        public InArgument<Entity> Entity { get; set; }
        
        public OutArgument<string> Link { get; set; }

        public CRM4GetLinkToEntity()
        {
            VisualBasicValue<Context> vbArgument = new VisualBasicValue<Context>(Constants.CONTEXT_NAME);
            this.Context = InArgument<Context>.FromExpression(vbArgument);
        }

        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            Entity entity = context.GetValue(this.Entity);
            Context con = context.GetValue(this.Context);

            CRM4Connector conn = (CRM4Connector)con.Connector[entity.System];
            context.SetValue(this.Link, conn.getLinkToEntity(entity));
        }
    }
}
